<?php
/**
 *
 *
 * @author AnthonyYang
 */
class ApplicationBehavior extends CBehavior
{
	
	/**
	 * 
	 * 
	 * @author AnthonyYang
	 * @access public
	 * @return void
	 */
	public function events()
	{
		return array_merge(parent::events(),array(
			'onBeginRequest' => 'beginRequest',
		));
	}
	
	/**
	 * @param CEvent $event
	 * 
	 * @author AnthonyYang
	 * @access public
	 * @return void
	 */
	public function beginRequest ($event)
	{
		if ($event->sender instanceof CWebApplication) {
			$webroot = Jii::getPathOfAlias('webroot');
			
			$event->sender->setTheme('default');
			$event->sender->getThemeManager()->setBasepath("{$webroot}/themes");
			$event->sender->setControllerPath("{$webroot}/protected/controllers");
			$event->sender->setViewPath("{$webroot}/protected/views");
			$event->sender->setLayoutPath(Jii::getPathOfAlias('application').'/layouts');
			$event->sender->setExtensionPath("{$webroot}/protected/extensions");
			$event->sender->setRuntimePath("{$webroot}/protected/runtime");
		}
	}
}